//一级路由
import Detail from '@/views/Detail/index.vue';
import Home from '@/views/Home/index.vue';
import Search from '@/views/Search/index.vue';
import Login from '@/views/Login/index.vue';
import Register from '@/views/Register/index.vue';
import AddCartSuccess from '@/views/AddCartSuccess/index.vue';
import ShopCart from '@/views/ShopCart/index.vue';
import Trade from '@/views/Trade/index.vue';
import Pay from '@/views/Pay/index.vue';
import PaySuccess from '@/views/PaySuccess/index.vue';
import Center from '@/views/Center/index.vue';

//二级路由
import MyOrder from '@/views/Center/MyOrder/index.vue';
import GroupOrder from '@/views/Center/GroupOrder/index.vue';

export default [
  {
    path: "/center",
    component: Center,
    meta: {show: true},
    children: [
      {
        path: "myOrder",
        component: MyOrder
      },
      {
        path: "groupOrder",
        component: GroupOrder
      },
      {
        path: "/center",
        redirect: "/center/myOrder"
      }
    ]
  },
  {
    path: "/paysuccess",
    component: PaySuccess,
    meta: {show: true},
    beforeEnter: (to, from, next) => {
      //去支付成功页面，必须来自支付页面
      if (from.path === "/pay") {
        next()
      } else {
        next(false)
      }
    }
  },
  {
    path: "/pay",
    component: Pay,
    meta: {show: true},
    beforeEnter: (to, from, next) => {
      //去支付页面，必须来自交易页面
      if (from.path === "/trade") {
        next()
      } else {
        //不是来在于交易页面，先去交易页面
        next("/trade")
      }
    }
  },
  {
    path: "/trade",
    component: Trade,
    meta: {show: true},
    beforeEnter: (to, from, next) => {
      //去交易页面，必须来自购物车页面
      if (from.path === "/shopcart") {
        next()
      } else {
        //不是来在于购物车，先去购物车页面
        next("/shopcart")
      }
    }
  },
  {
    path: "/shopcart",
    component: ShopCart,
    meta: {show: true}
  },
  {
    path: "/addcartsuccess",
    name: "addcartsuccess",
    component: AddCartSuccess,
    meta: {show: true}
  },
  {
    path: "/detail/:skuId",
    name: "detail",
    component: Detail,
    meta: {show: true}
  },
  {
    path: "/home",
    component: Home,
    meta: {show: true}
  },
  {
    path: "/search/:keyword?",
    component: Search,
    meta: {show: true},
    name: "search"
  },
  {
    path: "/login",
    component: Login,
    meta: {show: false}
  },
  {
    path: "/register",
    component: Register,
    meta: {show: false}
  },
  // 根路径重定向到首页
  {
    path: "/",
    redirect: "/home"
  }
]
